//
//  AppendDetailsHeaderView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/6.
//

#import "AppendDetailsHeaderView.h"
@interface AppendDetailsHeaderView ()
@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) UILabel * alarmStatus;
@property (nonatomic ,strong) UILabel * breedType;

@property (nonatomic ,strong) UILabel * xjCount;
@property (nonatomic ,strong) UILabel * ctCount;
@property (nonatomic ,strong) UILabel * tmCount;
@property (nonatomic ,strong) UILabel * umCount;
@property (nonatomic ,strong) UIImageView * yqimg;
@end
@implementation AppendDetailsHeaderView


+ (instancetype)initview {
    AppendDetailsHeaderView * view = [AppendDetailsHeaderView new];
    view.clipsToBounds = YES;
    [view setupView];
    return view;
}
- (void)setupView{
    MJWeakSelf
    UIView * makeview = [UIView new];
    makeview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(7) andView:makeview];
    [self addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(8));
        make.right.offset(kwt(-8));
        make.top.offset(kwt(10));
        make.bottom.offset(kwt(-10));
    }];
    
    UIImageView * yqimg = kimageView(@"delayed");
    [self addSubview:yqimg];
    self.yqimg = yqimg;
    [yqimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(kwt(64));
        make.right.offset(kwt(-2));
        make.top.equalTo(makeview.mas_top);
        make.height.offset(kwt(36));
    }];
    
    UIView * leftline = [UIView new];
    leftline.backgroundColor = KcolorHex(@"#0967FF");
    [DTKTool BFYJ:kwt(2) andView:leftline andCorner:UIRectCornerTopRight|UIRectCornerBottomRight andSize:CGRectMake(0, 0, kwt(4), kwt(15))];
    [makeview addSubview:leftline];
    [leftline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.offset(kwt(16));
        make.height.offset(kwt(15));
        make.width.offset(kwt(4));
    }];
    
    
    UILabel * name = [DTKTool labelWithText:@"--" andFont:kCFont(19) andTextColor:KcolorHex(@"#121212")];
    self.name = name;
    [makeview addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(14));
        make.height.offset(kwt(19));
    }];
    
    UILabel * alarmStatus = [DTKTool labelWithText:@"--" andFont:kCFont(13) andTextColor:KcolorHex(@"#0967FF")];
    self.alarmStatus = alarmStatus;
    [DTKTool YJ:kwt(2) andView:alarmStatus];
    alarmStatus.textAlignment = NSTextAlignmentCenter;
    [makeview addSubview:alarmStatus];
    [alarmStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(name.mas_right).offset(kwt(4));
        make.centerY.equalTo(name);
        make.width.offset(kwt(48));
        make.height.offset(kwt(20));
    }];
    UILabel * breedType = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#535353")];
    self.breedType = breedType;
    breedType.numberOfLines = 0;
    [makeview addSubview:breedType];
    [breedType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.width.offset(kwt(330));
        make.top.offset(kwt(48));
    }];
    
    UIView * leftview = [UIView new];
   
    [makeview addSubview:leftview];
    leftview.backgroundColor = KcolorHex(@"#F6F6F6");
    [DTKTool YJ:kwt(7) andView:leftview];
    [leftview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.height.offset(kwt(63));
        make.bottom.offset(kwt(-12));
        make.width.offset(kwt(248));
    }];
    
    UILabel * templab1 = [DTKTool labelWithText:@"投苗记录" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [leftview addSubview:templab1];
    [templab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(14));
        make.top.offset(kwt(39));
    }];
    UILabel * tmCount = [DTKTool labelWithText:@"-" andFont:kCFont(24) andTextColor:KcolorHex(@"#121212")];
    self.tmCount = tmCount;
    [leftview addSubview:tmCount];
    [tmCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(templab1);
        make.top.offset(kwt(9));
    }];
    templab1.addClickBlock(^{
        [weakSelf openTM];
    });
    tmCount.addClickBlock(^{
        [weakSelf openTM];
    });
    
    UILabel * templab2 = [DTKTool labelWithText:@"出塘记录" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [leftview addSubview:templab2];
    [templab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(39));
    }];
    UILabel * ctCount = [DTKTool labelWithText:@"-" andFont:kCFont(24) andTextColor:KcolorHex(@"#121212")];
    self.ctCount = ctCount;
    [leftview addSubview:ctCount];
    [ctCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(templab2);
        make.top.offset(kwt(9));
    }];
    templab2.addClickBlock(^{
        [weakSelf openCTJL];
    });
    ctCount.addClickBlock(^{
        [weakSelf openCTJL];
    });
    UILabel * templab3 = [DTKTool labelWithText:@"巡检记录" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [leftview addSubview:templab3];
    [templab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-11));
        make.top.offset(kwt(39));
    }];
    UILabel * xjCount = [DTKTool labelWithText:@"-" andFont:kCFont(24) andTextColor:KcolorHex(@"#121212")];
    self.xjCount = xjCount;
    [leftview addSubview:xjCount];
    [xjCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(templab3);
        make.top.offset(kwt(9));
    }];
    
    templab3.addClickBlock(^{
        [weakSelf openXJ];
    });
    xjCount.addClickBlock(^{
        [weakSelf openXJ];
    });
    UIView * rightview = [UIView new];
    [makeview addSubview:rightview];
    rightview.backgroundColor = KcolorHex(@"#F6F6F6");
    [DTKTool YJ:kwt(7) andView:rightview];
    [rightview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.height.offset(kwt(63));
        make.bottom.offset(kwt(-12));
        make.left.equalTo(leftview.mas_right).offset(kwt(8));
    }];
    
    UILabel * templab4 = [DTKTool labelWithText:@"今日任务" andFont:kFont(13) andTextColor:KcolorHex(@"#787A79")];
    [rightview addSubview:templab4];
    [templab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-11));
        make.top.offset(kwt(39));
    }];
    UILabel * umCount = [DTKTool labelWithText:@"-" andFont:kCFont(24) andTextColor:KcolorHex(@"#FA2D32")];
    self.umCount = umCount;
    [rightview addSubview:umCount];
    [umCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(templab4);
        make.top.offset(kwt(9));
    }];
    
}

- (void)openTM{
    if(self.openRZBlock){
        self.openRZBlock(1);
    }
}
- (void)openCTJL{
    if(self.openRZBlock){
        self.openRZBlock(4);
    }
}
- (void)openXJ{
    if(self.openRZBlock){
        self.openRZBlock(2);
    }
}
- (void)setModel:(AppendDetailsModel *)model{
    _model = model;
    self.name.text = model.name;
    ///告警状态 -1.正常 0.紧急、1.异常

    if(model.alarmStatus == 1){
        self.alarmStatus.text = @"异常";
        self.alarmStatus.textColor = KcolorHex(@"#F61A1A");
        self.alarmStatus.backgroundColor = KcolorHex(@"#FFE6E6");
    } else  if(model.alarmStatus == 0 ){
        self.alarmStatus.text = @"紧急";
        self.alarmStatus.textColor = KcolorHex(@"#F61A1A");
        self.alarmStatus.backgroundColor = KcolorHex(@"#FFE6E6");
    } else {
        self.alarmStatus.text = @"正常";
        self.alarmStatus.textColor = KcolorHex(@"#0967FF");
        self.alarmStatus.backgroundColor = KcolorHex(@"#E0ECFF");
    }
    [self.breedType mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.breedTypeH);
    }];
    if(model.typeCode == 1){
        self.breedType.text = [NSString stringWithFormat:@"养殖品种:%@", model.breedType];
    } else {
        self.breedType.text = @"";
    }
    self.yqimg.hidden = (model.isPostponed == 0);
    
    self.ctCount.text = [NSString stringWithFormat:@"%lu", model.pondTaskCountModel.ctCount];
    self.xjCount.text = [NSString stringWithFormat:@"%lu", model.pondTaskCountModel.xjCount];
    self.tmCount.text = [NSString stringWithFormat:@"%lu", model.pondTaskCountModel.tmCount];
    self.umCount.text = [NSString stringWithFormat:@"%lu", model.pondTaskCountModel.sumCount];

}
@end
